<script type="text/javascript" src="<?php echo URL::base(); ?>media/js/jquery.min.js"></script>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/js/jquery.json-2.4.js"></script>
<style>
#txtHint{ position:absolute; top:30px; left:0; display:none; background-color: #EDFAF4;min-width:281px; border: 1px solid #aaa; border-radius:5px;height:150px;overflow-x: hidden;}
#txtHint  li{ list-style:none; color:#333;border: 1px solid #EDFAF4;padding: 0px 8px;}
#txtHint  li:hover{  color:#c37100; background-color:#fdf8d5; border:1px solid #fac900; border-radius:25px;}
#detail span:hover{ color:#c37100;}
#group {position:relative;}
.table1 thead tr th,.table1 tbody tr td{ text-align:center;}
</style>
<body id="pageContent" class="well">    
                  <div class="form-horizontal">
													<div  class="control-group">
														<label class="control-label" for="input01">单据号码:</label>
                                <div class="controls">
                                  <input type="text" class="input-xlarge"  id="purchaseorder_id" id="" value="<?php if(isset($purchase_array))echo $purchase_array;?>" readonly="true"/>
                                </div>
													</div>
													<div class="control-group" >
														<label class="control-label" for="input01" >供应商:</label>
                                <div class="controls" id="group">
                                  <input type="text" class="input-xlarge"  name="supplier_id" id="supplier_id" value="" autocomplete="off"  />
																	<div id="txtHint" style="z-index:222px"></div>
                                </div>
													</div>
													<div class="control-group">
														<label class="control-label" for="input01">付款方式:</label>
                                <div class="controls">
                                  <select class="input-xlarge"  name="paytype" id="select" style="width: 284px" disabled>
                                	<option value="0">选择付款方式</option>
                                      <?php
                                      /**
                                       * 付款方式修改
                                       * @time 20140813
                                       * 对付款方式判断有影响
                                       */
                                      foreach ($pay_ways as $pay_way){?>
                                          <option value="<?php echo $pay_way['id']?>">
                                              <?php echo $pay_way['pay_way']?>
                                          </option>
                                      <?php }?>
                                    <?php
                                    /**
                                     * 之前是使用固定的付款方式，
                                     * 更改为从数据库获取的信息
                                     */
                                    /*<option value="货到付款">货到付款</option>
                                    <option value="周结">周结</option>
                                    <option value="网上支付">网上支付</option>
                                    <option value="款到发货">款到发货</option>
                                    <option value="月结">月结</option>
                                    <option value="货到付现">货到付现</option>
                                    <option value="货到转账">货到转账</option>
                                    <option value="半月结">半月结</option>
                                    <option value="月结45天">月结45天</option>
                                    <option value="月结30天">月结30天</option>
                                    <option value="月结60天">月结60天</option>*/
                                    ?>
                                  </select>
                                </div>
													</div>
													<div class="control-group">
														<label class="control-label"  for="input01">运费:</label>
                                <div class="controls">
                                  <input type="text" class="input-xlarge" onkeyup="clearNoNum(this)"  name="transportation_expense" id="transportation_expense" value="0" />
                                </div>
													</div>
                          <div class="control-group">

                                <!-- Textarea -->
                                <label class="control-label">备注:</label>
                                <div class="controls">
                                        <textarea type="" class="" style="margin: 0px; width: 272px; height: 90px;resize:none;" name="remark"  id="remark"> </textarea>
                                  </div>
                                </div>
													<div class="control-group" style="display:none">
														<label class="control-label" for="input01"></label>
                                <div class="controls">
                                  <input type="text" class="input-xlarge"  name="supplier" id="supplier" value="" />
                                </div>
													</div>
                  </div>
           <table class="table table1 table-hover table-striped table-condensed">
            <thead>
              <tr style="  background-color:#4EA392; color:#fff;">
                <th>
                  选择
                </th>
                <th>
                  SKU
                </th>
                <th>
                  中文名称
                </th>
                <th>
                  单位
                </th>
                <th>
                  储位
                </th>
                <th>
                  计税方式
                </th>
                <th>
                  单价
                </th>
                <th>
                  数量
                </th>
                <th>
                  税率
                </th>
                <th>
                  金额
                </th>
								<th>
									交货日期
								</th>
                  <th>
                      系统成本价
                  </th>
                  <th>
                      状态
                  </th>
                <th>
                  <button class="btn btn-info" onclick="add()">新增</button>
                </th>
                
              </tr>
            </thead>
            <tbody id="row">
              <tr id="a">
                <td >
                  <input type="checkbox" name="choose" value=""  onclick='add_auto(this)'>
                </td>
                <td>
                   <input style="width:70px;" class="input-mini" type="text" value="" /> 
                </td>
                <td>                  
                  
                </td>
                <td>
                  
                </td>
                <td>
                  
                </td>
									
                <td>
                  <select class="input-xlarge tax_way"  name="tax_way" id="tax_way" style="width: 75px">
                                    <option value="0">不计税</option>	
	                                	<option value="-1">内含税</option>
                                    <option value="1">外加税</option>
									</select>
                </td>
								<td>
									<input class="input-mini" type="text" value=''  style="width:40px" onBlur='atotle_s_price(this)' />
								</td>
                <td>
                  <input class="input-mini" type="text" value='' style="width:40px" onkeyup="key_up(this)" onafterpaste="key_paste()" onBlur="atotle_price(this)"/>
                </td>
                <td>
                  <input class="input-mini tax_rate"   onkeyup="clearNoNum(this)"  type="text" value='0' />%
                </td>
                <td>
                  <input class="input-mini" type="text" value='' disabled="disabled"/>
                </td>
								<td>
									<input class="input-mini datepicker" type="text" value=''  style="width:80px"  />
								</td>
                  <td>

                  </td>
                <td>
					
				</td>
                <td>
                  <button class="btn btn-info" onclick="delete_remove(this)">删除</button>
                </td>
              </tr>
            </tbody>
         
          </table>
					<div><input style=" margin:0; margin-right:5px;" type="checkbox" id="chooseall" />全选  <button id="tijiao" class="btn btn-info tijiao" style="margin-left:10px;">一键创建</button></div>
</body>
<?php if(isset($id)){?>
<br />
							<div id="detail">
									<span >采购单<?php echo $id; ?>详情</span>
							</div>
							<hr />
							<div id="result" style="display:none">

							</div>
<?php }?>
<script type="text/javascript">

//$('.table1 > tbody > tr > td').eq(9).toFixed(2);
//税率改变改变金额
$(document).on('blur',".tax_rate", function(e){
		$(this).css("background-color","#D6D6FF");
  	var obj    = $(this).parent().parent();
		var number = obj.children('td').eq(7).find('input').val();
		var price  = obj.children('td').eq(6).find('input').val();
		if(obj.children('td').eq(5).find('select').val()==1)
		{
			 var total	= (Number(number)*Number(price)*(1+Number(obj.children('td').eq(8).find('input').val())/100)).toFixed(2);
			 obj.children('td').eq(9).html(total);
		}else{
			 var total	= (Number(number)*Number(price)).toFixed(2);
			 obj.children('td').eq(9).html(total);
	}							 						
});
//计税方式改变金额
$(document).on('change',".tax_way", function(e){
  $(this).css("background-color","#FFFFCC");
  	var obj    = $(this).parent().parent();
		var number = obj.children('td').eq(7).find('input').val();
		var price  = obj.children('td').eq(6).find('input').val();
		if(obj.children('td').eq(5).find('select').val()==1)
		{
			 var total	= (Number(number)*Number(price)*(1+Number(obj.children('td').eq(8).find('input').val())/100)).toFixed(2);
			 obj.children('td').eq(9).html(total);
		}else{
			 var total	= (Number(number)*Number(price)).toFixed(2);
			 obj.children('td').eq(9).html(total);
	}							 						
});
/*$(".tax_rate").blur(function(){
  $(this).css("background-color","#D6D6FF");
  var obj    = $(this).parent().parent();
	if($(this).parent().prev().children().val()==1)
	{
		 var number = obj.children('td').eq(4).find('input').val();
		 var price  = obj.children('td').eq(3).find('input').val();
		 var total	= (Number(number)*Number(price)*(1+Number(obj.children('td').eq(7).find('input').val()))).toFixed(2);
		 var totals =(Number($("#p_id").children('td').eq(5).html())-Number(obj.children('td').eq(5).html())+Number(total)).toFixed(2);
		 obj.children('td').eq(5).html(total);
		 $("#p_id").children('td').eq(5).html(totals);	
	}else{
		 var number = obj.children('td').eq(4).find('input').val();
		 var price  = obj.children('td').eq(3).find('input').val();
		 var total	= (Number(number)*Number(price)).toFixed(2);
		 var totals =(Number($("#p_id").children('td').eq(5).html())-Number(obj.children('td').eq(5).html())+Number(total)).toFixed(2);
		 obj.children('td').eq(5).html(total);
		 $("#p_id").children('td').eq(5).html(totals);			

	}
});
$(".field").change(function(){
  $(this).css("background-color","#FFFFCC");
	if($(this).val()==1)
	{
		 var obj    = $(this).parent().parent();
		 var number = obj.children('td').eq(4).find('input').val();
		 var price  = obj.children('td').eq(3).find('input').val();
		 var total	= (Number(number)*Number(price)*(1+Number(obj.children('td').eq(7).find('input').val()))).toFixed(2);
		 var totals =(Number($("#p_id").children('td').eq(5).html())-Number(obj.children('td').eq(5).html())+Number(total)).toFixed(2);
		 obj.children('td').eq(5).html(total);
		 $("#p_id").children('td').eq(5).html(totals);	
	}else{
		 var obj    = $(this).parent().parent();
		 var number = obj.children('td').eq(4).find('input').val();
		 var price  = obj.children('td').eq(3).find('input').val();
		 var total	= (Number(number)*Number(price)).toFixed(2);
		 var totals =(Number($("#p_id").children('td').eq(5).html())-Number(obj.children('td').eq(5).html())+Number(total)).toFixed(2);
		 obj.children('td').eq(5).html(total);
		 $("#p_id").children('td').eq(5).html(totals);	

	}
});*/
//查询采购详情
	$("#detail span").click(function(){
		var id = "<?php echo isset($id)?$id:'';?>";
		if(document.getElementsByTagName("table").length>1)
		{			
			$("#purchase_order").remove();return ;
		}
		$.ajax({
					type:'POST',
					dataType:"json",
					url:"<?php echo URL::site() ?>purchase/detail_purchase",
					async:false,
					data:{'id':id},
					success:function(data){
						$("#result").show();
						$("#result").html(data);
					}
				});
		
});	
	//默认时间日期
$(document).ready(function(){
							$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
						

							$(document).on('focus',".datepicker", function(e){
							   var strs= new Array();
								var str = "<?php echo date('Y-m-d',time());?>";
							 	strs=str.split("-");
							 								$(this).datepicker({
							 								minDate: new Date(strs[0], strs[1]-1, strs[2]),
							 							});  
								});
							//$("#date_from").val('<?php echo isset($date_from)?$date_from:""; ?>');
							//$("#date_to").val('<?php echo isset($date_to)?$date_to:""; ?>');
							$("#purchaseorder_id").val('<?php echo isset($purchaseorder_id)?$purchaseorder_id:""; ?>');
});
//由sku找查询相关信息
	$(document).on('keydown',".input-mini", function(e){
	var key = e.which;
	var id  =  $(this).parent().parent().attr('id');
	if($(this).parent().index()!=1)
	{
		return ;
	}
	if($("#supplier_id").val()=="")
	{
		return ;
	}
	if(key==13)
	{
			$.ajax({
					type:'POST',
					dataType:"json",
					url:"<?php echo URL::site() ?>purchase/select_sku",
					async:false,
					data:{'sku':$(this).val(),'supplier_id':$("#supplier_id").val()},
					success:function(data){
						if(!data)
						{
								alert("sku不存在");return ;
						}
						
						$.each(data,function(key,value){//'price','iproviderID','nuit','ID','delivery'
					if(key=='products_sku')
					{
						$("#"+id).children().eq(1).find("input").val(value);
					}
					else if(key == 'products_name_cn')
					{
						$("#"+id).children().eq(2).html(value);
					}
					else if(key == 'price')
					{
						$("#"+id).children().eq(6).find("input").val(value);
					}
					else if(key== 'iproviderID')
					{
						$("#supplier").val(value);
					}			
					else if(key=='nuit')
					{
						$("#"+id).children().eq(3).html(value);
					}
					else if(key=='delivery'){
						$("#"+id).children().eq(10).find("input").val(value);
					}
					else if(key=='products_storage'){
						$("#"+id).children().eq(4).html(value);
					}
					else if(key=='payment'){
						/*$("#select option[value="+value+ "]").attr('selected',"selected");
						if($("#select").val()==0)
						{
							$("#select").attr("disabled",false);
						}
						else
							$("#select").attr("disabled",true);*/								
					}					
					$("#supplier_id").attr({ readonly: 'true' });
					$("#"+id).children().eq(1).find("input").attr({ readonly: 'true' });
				});					
				
				//	window.location.reload();
				},		
				});
	}else
	{
		return ;
	}
}); 
//由sku找查询相关信息
	$(document).on('blur',".input-mini", function(e){
	//var key = e.which;
	var id  =  $(this).parent().parent().attr('id');
	if($(this).parent().index()!=1)
	{
		return ;
	}
	if($("#supplier_id").val()=="")
	{
		alert("供应商为空");return ;
	}
			$.ajax({
					type:'POST',
					dataType:"json",
					url:"<?php echo URL::site() ?>purchase/select_sku",
					async:false,
					data:{'sku':$(this).val(),'supplier_id':$("#supplier_id").val()},
					success:function(data){
						if(!data)
						{
								alert("SKU与供应商不匹配!");return ;
						}
						$.each(data,function(key,value){//'price','iproviderID','nuit','ID','delivery'
					if(key=='products_sku')
					{
						$("#"+id).children().eq(1).find("input").val(value);
					}
					else if(key == 'products_name_cn')
					{
						$("#"+id).children().eq(2).html(value);
					}
					else if(key == 'price')
					{
						$("#"+id).children().eq(6).find("input").val(value);
					}
					else if(key== 'iproviderID')
					{
						$("#supplier").val(value);
					}			
					else if(key=='nuit')
					{
						$("#"+id).children().eq(3).html(value);
					}
					else if(key=='delivery'){
						$("#"+id).children().eq(10).find("input").val(value);
					}
					else if(key=='products_place'){
						$("#"+id).children().eq(4).html(value);
					}
					else if(key=='payment'){
						//$("#select option[value="+value+ "]").attr('selected',"selected");
						//$("#select option[value="+data['payment']+ "]").attr('selected',"selected");
					}else if(key=='products_values'){
                        $("#"+id).children().eq(11).html(value);
                    }else if(key=='status'){
						$("#"+id).children().eq(12).html(value);
					}
					$("#supplier_id").attr({ readonly: 'true' });
					$("#"+id).children().eq(1).find("input").attr({ readonly: 'true' });
				});					
				
				//	window.location.reload();
				},		
				});

}); 
//	$(".tijiao").click(function(){		
//		if(ids=='-'){
//			alert("请选择");
//			return;
//		}else{
//			var strs= new Array();
//			strs=ids.split("-");
//			var supplier=$("#supplier_id").val();
//			var arr = new Array();
//			for(var i=0;i<(strs.length-1);i++)
//			{
//				arr[i]=i;
//			}
//			alert($("#supplier_id").val());
//			return;
//		}
//	});
//批量全选创建
	$("#tijiao").click(function(){		
			if(ids=='-'){
				alert("请选择");
				return;
			}else{
				var strs= new Array();
				strs=ids.split("-");
				var arr = new Array();
				for(var i=0;i<(strs.length-1);i++)
				{
						if(i==0)
						{
							arr[i] ={'supplier_id':$("#supplier").val(),'pay_way':$("#select").val(),'transportation_expense':$("#transportation_expense").val(),'remark':$("#remark").val()
										}
							var mark = judge_supplier(arr[i]);
							if(!mark)
							{
								return ;
							}
						}else{
							arr[i] = {
							'tax_rate':$("#"+strs[i]).children('td').eq(8).find("input").val(),
							'arrive_date':$("#"+strs[i]).children('td').eq(10).find("input").val(),
							'tax_way':$("#"+strs[i]).children('td').eq(5).find("select").val(),
							'sku':$("#"+strs[i]).children('td').eq(1).find("input").val(),
							//'sku_name':$("#"+strs[i]).children('td').eq(2).html(),
							'quantity':$("#"+strs[i]).children('td').eq(7).find("input").val(),
							'supplier':$("#supplier").val(),
							'single_price':$("#"+strs[i]).children('td').eq(6).find("input").val(),
						}
							var flag = valicate_data(arr[i]);
							if(!flag)
							{
								return ;
							}
					}
				}//alert("stringeee");				
				var jdata=$.toJSON(arr);
				$.ajax({
					type:'POST',
					dataType:"json",
					url:"<?php echo URL::site() ?>purchase/addpurchase",
					async:false,
					data:{json:jdata},
					success:function(result){				
						alert("采购单"+result+"成功创建");
						var url ="<?php echo  URL::site() ?>purchase/index?"+"id="+result;
					window.location.replace(url);
				},		
				});
			}		
	});
	$("input[type='checkbox']").each(function(){
		if(this.checked){
			this.checked=false;
		}
	});
	var ids="-";

	//点击全选和全不选
	$("#chooseall").click(function(){
		if(this.checked){ 
			$("input[name='choose']").each(function(){
				this.checked=true;
						
				//如果该复选框已经被选择，则获取其采购单的ID
				if(this.checked){
					var id=$(this).parent().parent().attr('id');
					if(ids.indexOf(id)==-1){
							ids=ids+id+"-";
					}
				}
			});
		}else{ 
				ids="-";
				$("input[name='choose']").each(function(){
					this.checked=false;
				}); 
		}
	});

		//点击单个单选按钮将其id拼入或者删除
	function add_auto(obj)
	{
			var id=$(obj).parent().parent().attr('id');
			if(obj.checked){
				if(ids.indexOf(id)==-1){
					ids=ids+id+"-";
				}
				
			}else{
				var index=ids.indexOf(id);
				if(index!=-1){
					var idremove=ids.substr(index,id.length);
					var reg="-"+idremove+"-";
					ids=ids.replace(new RegExp(reg),"-");
				}
			}
	}
		var i=0;
//搜索提示
    $(function(){
        $("#supplier_id").keyup(function(e){
            var $val=$(this).val();
          
            showHint($val);
            
            
        });
    })
    function showHint(str){
        if(str.length==0){
            $("#supplier_id").val('');
            return false;
        }
        var url="<?php echo URL::base() ?>purchase/select_supplier";
        url+="?name="+str;
        url+="&sid="+Math.random();
        $.getJSON(url,function(data){
						if(data==0)
						{
								$("#txtHint").hide();
								return ;
						}
            $("#txtHint").html("");
            var $array=data.split(',');
            $.each($array,function(index,value){
                $('<li>'+value+'</li>').appendTo($("#txtHint"));
                $("#txtHint").show();
            });
        });
    }
//提示结果选择
$(document).on('click',"#txtHint li", function(e){
                    $("#supplier_id").val($(this).text());
                    $(this).parent().hide();
										var urls="<?php echo URL::base() ?>purchase/select_payment";
										urls+="?name="+$(this).text();
										$.getJSON(urls,function(data){
														var flag = false;
														$("#select option").each(function (i) {
                    							document.getElementById("select").options[i].removeAttribute("selected");
																	if(data==document.getElementById("select").options[i].value)
																		flag = true;
            									}
            								);
														if(flag)
														{
															$("#select option[value="+data+"]").attr('selected',"selected"); 
															if($("select").val()==0)
															{
																$("#select").attr("disabled",false);
															}
															else
															{
																$("#select").attr("disabled",true);
															}
														}else{
															$("#select").attr("disabled",false);
														}						
										});
});
//新增一栏
function add()
{
	i++;
	var html = "<tr id="+i+"> ";
	html+="<td id="+i+"><input type='checkbox' name='choose' value='' onclick='add_auto(this)'></td>";
	html+="<td><input style='width:85px;' type='text' value='' class='input-mini'></td>";
	html+="<td></td>";
	html+="<td></td>";
	html+="<td></td>";
	html+= "<td><select class='input-xlarge tax_way' name='tax_way' id='tax_way' style='width: 75px'><option value='0'>不计税</option><option value='-1'>内含税</option><option value='1'>外加税</option></td>";
	html+= "<td><input class='input-mini' type='text' value=''  style='width:40px' onBlur='atotle_s_price(this)'></td>";
	html+= '<td><input class="input-mini" type="text" value="" style="width:40px"  onkeyup="key_up(this)" onafterpaste="key_paste()" onBlur="atotle_price(this)"></td>';
	html+= "<td><input class='input-mini tax_rate' type='text' value='0' >%</td>";
	html+= "<td><input class='input-mini' type='text' value='' disabled='disabled'></td>";
	html+= "<td><input class='input-mini datepicker' type='text' value=''  style='width:80px'  ></td>";
	html+="<td></td>";
	html+="<td></td>";
	html+= "<td><button class='btn btn-info' onclick='delete_remove(this)'>删除</button></td>";
	html+= "</tr>";
       
	$("#row").append(html);
}
//判断创建的采购单信息
function judge_supplier(arr)
{
	var flag='';
	$.each(arr,function(key,value){
		if(key=='supplier_id'&&value=='')
		{
			if($("#supplier_id").val!="")
			{
				flag = "名称为空";
			}else{
				flag = "供应商为空";
			}
		}
		else if(key=='pay_way'&&value==0)
		{
			flag ="未选择付款方式";
		}		
		else if(key=='transportation_expense'&&(!judge(value)||value<0))
		{
			if(!judge(value))
				flag ="运费不是数字";
			else
				flag ="运费小于0";
		}
		if(flag)
		{
			alert(flag);return false;
		}
	});
		if(flag) return false ;
		return true;
}
function valicate_data(arr)
{
	var flag='';		
	$.each(arr,function(key,value){

		if(key=='tax_rate'&&value!='0')
		{
			if(!judge(value))
			{
				alert("税率不是数字");
				flag = 1;
			}
			if((parseInt(value)>100)||(parseInt(value)<0))
			{
				alert("税率超出范围(0～100)");
				flag = 1;
			}		

		}
		else if(key=='arrive_date'&&value=='')
		{
			//flag ="";
		}
		else if(key=='tax_way'&&value==0)
		{
			//flag ="";
		}	
		else if(key=='sku'&&value=='')
		{
			alert("未填sku");
			flag=1;
		}	
		else if(key=='sku_name'&&value=='')
		{
			alert("供应商与sku不匹配!");
			flag =1;
		}
		else if(key=='quantity'&&(value==''||value==0))
		{
			alert("未填数量"); flag=1;
		}	
		else if(key=='supplier'&&value==0)
		{
			alert("未选择供应商");flag=1;
		}		
		else if(key=='single_price'&&(!judge(value)||value<=0))
		{
			if(!judge(value))
			{
				alert("单价不是数字");
				flag=1;
			}
			else
			{
				alert("单价小于等于0");
				flag=1;
			}
		}

		if(flag)
			return false;
	});
		if(flag) return false ;
	return true;
}
//判断数据
function judge(factpay){

	if(!isNaN(factpay)){
		return true;;
	}else{		
		return false;
	}
}
function key_up(obj)
{
	obj.value = obj.value.replace(/\D/g,'');
}
function key_paste()
{
	obj.value = obj.value.replace(/\D/g,'');
}
//数量改变造成总额改变
function atotle_price(obj)
{
	//
	
	var number=obj.value;//alert(number);return ;
	var noneprices=Number($(obj).parent().prev().find("input").val());
	var flag  = judge(noneprices);
	if(!flag)
	{
		alert("单价不是数字");return ;
	}
	var totles=Number(number*noneprices).toFixed(2);
	if($(obj).parent().prev().prev().find('select').val()==1)
	{
		totles = (totles*(1+Number($(obj).parent().next().find('input').val())/100)).toFixed(2);
	}
	if(number=="" ){
		//document.getElementById("totle_ids").value=0;
		}else{
			$(obj).parent().next().next().html(totles);	
		}
}
//单价改变造成总额改变
function atotle_s_price(obj)
{
	var noneprices=obj.value;
	var number=Number($(obj).parent().next().find("input").val());
	var flag  = judge(noneprices);
	if(!flag)
	{
		alert("单价不是数字");return ;
	}
	var totles=Number(number*noneprices).toFixed(2);
	if($(obj).parent().prev().find('select').val()==1)
	{
		totles = (totles*(1+Number($(obj).parent().next().next().find('input').val())/100)).toFixed(2);
	}
	if(number=="" ){
		//document.getElementById("totle_ids").value=0;
		}else{  
			$(obj).parent().next().next().next().html(totles);
	
		}
}
//删除一列
function delete_remove(obj)
{
	 		var id=$(obj).parent().parent().attr('id');
			if(obj.checked){
				if(ids.indexOf(id)==-1){
					ids=ids+id+"-";
				}
				
			}else{
				var index=ids.indexOf(id);
				if(index!=-1){
					var idremove=ids.substr(index,id.length);
					var reg="-"+idremove+"-";
					ids=ids.replace(new RegExp(reg),"-");
				}
			}
	 		$(obj).parent().parent().remove();
}
//判断单价
function clearNoNum(obj){   obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  

 obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是. 

  obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.   

obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
} 
</script>
			
